package com.hzbat.service.impl;

import java.util.List;

import javax.servlet.ServletContext;

import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;

import com.hzbat.service.BasicService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service("basicServiceImpl")
public abstract class BasicServiceImpl<T> implements BasicService<T>,ServletContextAware{
	
	private static final Integer PAGE_NUM = 1 ;
	private static final Integer PAGE_SIZE = 10 ;
	
	//实现ServletContextAware自动注入servlectContext上下文
	protected ServletContext servletContext;
	
	public void setServletContext(ServletContext servletContext){
		this.servletContext = servletContext ;
	}
	
	public ServletContext getServletContext() {
		return servletContext;
	}

	public PageInfo<T> getPage(Integer pageNum,Integer pageSize,T condition){
		int num = (pageNum==null?PAGE_NUM:pageNum);
		int size = (pageSize==null?PAGE_SIZE:pageSize);
		PageHelper.startPage(num, size);
		List<T> list = getList(condition);
		return new PageInfo<T>(list);
	}

	
}
